/*
 * Bat.Java, the bat which is controled by keyboard to move left/right
 */
package bounce;

import java.awt.Color;
import java.awt.Graphics;

/**
 *
 * @author PANAIMIN
 */
public class Bat {

    public static final int NORMAL_SIZE = 30;
    public static final int BIG_SIZE = 50;
    public static final int HIGHT = 3;

    public static Bat Instance() {
        if(_instance == null)
            _instance = new Bat();
        return _instance;
    }

    public void init() {
        _size = NORMAL_SIZE;
        _left = 450 - NORMAL_SIZE / 2;
    }

    public int left()                   { return _left; }
    public void leftLimit(int limit)    { _leftLimit = limit; }
    public void rightLimit(int limit)   { _rightLimit = limit; }
    public int size()                   { return _size; }
    public int center()                 { return _left + _size / 2; }
    public int right()                  { return _left + _size; }

    public void toggle() {
        _size = _size == NORMAL_SIZE ? BIG_SIZE : NORMAL_SIZE;
        Stage.Instance().repaint(0, _left, TOP, BIG_SIZE, HIGHT);
    }

    public void draw(Graphics g) {
        g.setColor(Color.RED);
        g.fillRect(_left, TOP, _size, HIGHT);
    }

    public void moveLeft() {
        _left -= STEP;
        if(_left < _leftLimit)
            _left = _leftLimit;
        Stage.Instance().repaint(0, _left, TOP, _size + STEP, HIGHT);
    }

    public void moveRight() {
        _left += STEP;
        if(_left + _size > _rightLimit)
            _left = _rightLimit - _size;
        Stage.Instance().repaint(0, _left - STEP, TOP, _size + STEP, HIGHT);
    }

    private Bat() {}

    private static Bat  _instance;
    private static int  STEP = 10;
    private static int  TOP = 600 - HIGHT;
    private int         _left = 450;
    private int         _size = NORMAL_SIZE;
    private int         _leftLimit = 0;
    private int         _rightLimit = 900;
}
